<html>
<head>
<title>Stock Quote From NASDAQ</title>
<link rel='stylesheet' type='text/css' href='./css/estilos.css' media='screen' />
</head>
<body>
<?php
include('conexion.php');
//choose stock to look at
$select = mysql_query("SELECT IDCompany FROM CompanyAssets");
while($symbol = mysql_fetch_array($select)){
		echo '<h1>Stock quote for ' . $symbol['IDCompany'] . '</h1>';
		$url = 'http://finance.yahoo.com/d/quotes.csv' .
		'?s=' . $symbol['IDCompany'] . '&e=.csv&f=sl1d1t1c1ohgv';
		if (!($contents = file_get_contents($url))) {
		die('Failure to open ' . $url);
		}
		// extract relavant data
		list($nombre, $quote, $date,$time,$change) = explode(',', $contents);
		$date = trim($date, '"');
		$time = trim($time, '"');
		$change = trim($change, '"');
		echo '<p>' . $symbol . ' was last sold at: ' . $quote . '</p>';
		echo '<p>Quote current as of ' . $date . ' at ' . $time . '</p>';
		// acknowledge source
		echo '<p>This information retrieved from <br /><a href="' . $url .
		'">' . $url . '</a>.</p>';

		if ($change >= 0 ){

		echo "<img src='./images/up_g.gif'></img><a class='pos'>".$change."</a>";

		}else{
		echo "<img src='./images/down_r.gif'></img>".$change;
		}
		
		$loadvalues = mysql_query("UPDATE CompanyAssets SET Value = '$quote', change = '$change' WHERE IDCompany = '{$symbol['IDCompany']}'");
		
		if (!$loadvalues){
			
				echo mysql_error($loadvalues);
			
			}
			
		
}
?>
</body>
</html>